package com.whj.apipassenger.interceptor;

import com.whj.internalcommon.constant.CommonStatusEnum;
import com.whj.internalcommon.dto.ResponseResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Auther: wanghaijun
 * @Date: 2023/11/5 - 11 - 05 - 19:51 
 * @Description: com.whj.apipassenger.interceptor
 */

@RestControllerAdvice
public class GolbalValidationExecptionHandler {

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseResult validationException(MethodArgumentNotValidException e) {

        return ResponseResult.fail(CommonStatusEnum.VALIDATION_EXCEPTION.getCode(),
                e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }
}
